package com.ychug.framework.business.service;

import com.ychug.service.system.entity.SysSerialNumberEntity;
import com.ychug.service.system.service.ISysSerialNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class SystemSerialNumber {


    @Autowired
    private ISysSerialNumberService iSysSerialNumberService;

    /**
     * 获取流水号
     * @param maxType
     * @param maxModel
     * @return
     */
    public String createSerialNumber (String maxType,String maxModel){

        int result = 0;
        SysSerialNumberEntity sysSerialNumberEntity = new SysSerialNumberEntity();
        sysSerialNumberEntity.setMaxModel(maxModel);
        sysSerialNumberEntity.setMaxType(maxType);

       List<SysSerialNumberEntity> list =  iSysSerialNumberService.selectSysSerialNumberList(sysSerialNumberEntity);
       if(list == null || list.size() < 1){
           sysSerialNumberEntity.setMaxNo(1);
           iSysSerialNumberService.insertSysSerialNumber(sysSerialNumberEntity);
           result =1;
       }else{
           SysSerialNumberEntity tempSysSerialNumberEntity = list.get(0);
           tempSysSerialNumberEntity.setMaxNo(tempSysSerialNumberEntity.getMaxNo()+1);
           iSysSerialNumberService.updateSysSerialNumber(tempSysSerialNumberEntity);
           result = tempSysSerialNumberEntity.getMaxNo();
       }

        return String.valueOf(result);
    }


}
